package com.basiclib.utils

import android.os.Environment
import java.io.File
import java.io.FileInputStream
import java.util.*

class RomUtils {
    enum class AvailableRomType {
        MIUI, FLYME, OPPO, ANDROID_NATIVE
    }

    companion object {
        fun getLightStatusBarAvailableRomType(): AvailableRomType {
            return try {
                val properties = Properties()
                properties.load(FileInputStream(File(Environment.getRootDirectory(), "build.prop")))
                val brand = properties.getProperty("ro.product.brand", null)
                if (!brand.isNullOrBlank()) {
                    when (brand) {
                        "xiaomi" -> AvailableRomType.MIUI
                        "meizu" -> AvailableRomType.FLYME
                        "oppo" -> AvailableRomType.OPPO
                        else -> AvailableRomType.ANDROID_NATIVE
                    }
                } else {
                    AvailableRomType.ANDROID_NATIVE
                }
            } catch (e: Exception) {
                AvailableRomType.ANDROID_NATIVE
            }
        }
    }
}

fun isMiUIV6OrAbove(): Boolean {
    try {
        val properties = Properties()
        properties.load(FileInputStream(File(Environment.getRootDirectory(), "build.prop")))
        val uiCode = properties.getProperty("ro.miui.ui.version.code", null)
        if (uiCode != null) {
            val code = Integer.parseInt(uiCode!!)
            return code >= 4
        } else {
            return false
        }

    } catch (e: Exception) {
        return false
    }
}